<template v-if="shopDetails">
  <div @click="changeTop" :class="{ cur: navIndex == 1 }">
    <div class="item">
      <div class="shopRatings">
        <div class="overview">
          <h5>3.5</h5>
          <p>综合评分</p>
          <p>高于附近商家99.20%</p>
        </div>
        <div class="right_shop_rating">
          <div class="rating">
            <div class="rating-item">
              <p class="content">服务态度</p>
              <div class="star">
                <div
                  class="img"
                  v-for="(item, index) of getStar(shopDetails.serviceScore)"
                  :key="index"
                  :class="item"
                ></div>
              </div>
              <span>4.1</span>
            </div>
            <div class="rating-item">
              <p class="content">综合评分</p>
              <div class="star">
                <div
                  class="img"
                  v-for="(item, index) of getStar(shopDetails.serviceScore)"
                  :key="index"
                  :class="item"
                ></div>
              </div>
              <span>4.1</span>
            </div>
            <div class="rating-item flexnone">
              <p class="content">到达时间</p>
              <span class="time">{{ shopDetails.deliveryTime }}分钟</span>
            </div>
          </div>
        </div>
      </div>
      <div class="blank"></div>
      <section v-if="ratings">
        <header>
          <mt-button
            @click.native="checkBtn(0)"
            :class="{ cur: currentIndex == 0 }"
            >全部{{ ratings.length }}</mt-button
          >
          <mt-button
            @click.native="checkBtn(1)"
            :class="{ cur: currentIndex == 1 }"
            >满意{{ satiLength }}</mt-button
          >
          <mt-button
            @click.native="checkBtn(2)"
            :class="{ cur: currentIndex == 2 }"
            >不满意{{ unSatiLength }}</mt-button
          >

          <!-- <footer>
            <mt-switch v-model="isReadContent" class="switch"
              >是否只看有内容的评论</mt-switch
            >
          </footer> -->
        </header>
        <section>
          <!-- comment content -->

          <div class="comments">
            <div class="comment-items" v-if="newRatings">
              <div
                class="comment-item"
                v-for="(item, index) of newRatings"
                :key="index"
              >
                <div class="left_avatar">
                  <img :src="item.avatar" alt="" />
                </div>
                <div class="right-content">
                  <header>
                    <div class="uname">{{ item.username }}</div>
                    <div class="time">2016-07-27 23:24:44</div>
                  </header>
                  <div class="star mt10">
                    <div
                      class="img2"
                      v-for="(item, index) of getStar(item.score)"
                      :key="index"
                      :class="item"
                    ></div>
                  </div>
                  <section class="content">
                    {{ item.text }}
                  </section>
                  <footer
                    style="
                      display: flex;
                      align-items: center;
                      margin-top: 10px;
                      flex-wrap: wrap;
                    "
                  >
                    <i
                      v-show="item.recommend.length > 0"
                      class="iconfont icon-zantianchong"
                      style="color: #ff8600; margin-right: 10px"
                    ></i>
                    <mt-button
                      class="foot-btn"
                      plain
                      size="small"
                      v-for="(text, i) of item.recommend"
                      :key="i"
                      >{{ text }}</mt-button
                    >
                  </footer>
                </div>
              </div>
            </div>
          </div>
        </section>
      </section>
    </div>
  </div>
</template>

<script>
import { ratings } from "../../apis/profile/profile";
export default {
  data() {
    return {
      navIndex: this.value,
      ratings: null,
      newRatings: null,
      isReadContent: false,
      currentIndex: 0,
    };
  },
  props: {
    value: Number,
    shopDetails: Object,
  },
  watch: {
    navIndex(nv) {
      this.$emit("input", nv);
    },
    value(nv) {
      this.navIndex = nv;
    },
    isReadContent(nval) {
      if (nval) {
      }
    },
  },
  components: {},

  computed: {
    satiLength() {
      return this.ratings.filter((item) => {
        return item.rateType == 0;
      }).length;
    },
    unSatiLength() {
      return this.ratings.filter((item) => {
        return item.rateType == 1;
      }).length;
    },
  },

  methods: {
    changeTop() {
      document.documentElement.scrollTop = 1000000000;
    },
    getStar(rating) {
      let stars = ["off", "off", "off", "off", "off"];
      if (isNaN(rating)) return stars;
      let floor = Math.floor(rating);
      for (var num = 0; num < floor; num++) {
        stars[num] = "on";
      }
      // 判断是否是 半颗星星
      let fixed1 = (rating % floor).toFixed(1);
      if (fixed1 > 0.3 && fixed1 < 0.8) {
        stars[num] = "half";
      }
      return stars;
    },
    checkBtn(index) {
      // 点击按钮
      this.currentIndex = index;

      // 00000000000000000000
      if (this.currentIndex == 0) {
        this.newRatings = this.ratings;
      } else if (this.currentIndex == 1) {
        this.newRatings = this.ratings.filter((item) => {
          return item.rateType == 0;
        });
      } else if (this.currentIndex == 2) {
        this.newRatings = this.ratings.filter((item) => {
          return item.rateType == 1;
        });
      }
    },
  },
  mounted() {
    ratings().then((response) => {
      this.ratings = response.data.data;
      this.checkBtn(this.currentIndex);
    });
  },
};
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped>

// 星星
@import ("../../stylus/mixns.styl");
.half
  bg-image('../../assets/images/stars/star48_half')
.off
  bg-image('../../assets/images/stars/star48_off')
.on
  bg-image('../../assets/images/stars/star48_on')

p,
h5
  margin: 0

.item
  .shopRatings
    display: flex
    align-items: center;
    height: 140px;
    border-bottom :1px solid #eee;
    .overview
      width: 40%
      text-align: center;
      border-right: 2px solid #eee;
      h5
        font-size: 25px;
        color: #ff8600;
      p:first-of-type
        margin:5px 0;
        color: #111
        font-size:15px;
      p:last-of-type
        color:#8e8989;

        font-size:13px;
    .right_shop_rating
      width: 60%
      .rating
        margin-left: 20px;
        margin-right: 10px;
        margin-top: 5px

        .rating-item
          font-size:14px;
          margin-top: 8px
          display: flex;
          justify-content: space-between;
          align-items: center
          .content
            // margin-right: 10px;

          span
            color #ff8600
            font-size: 15px;
            font-weight: bold

          .time
            color:#8e8989;
          &.flexnone
            justify-content: flex-start !important;
            .time
              margin-left: 15px;
              font-weight:300
  .blank
    background-color: rgb(243, 244, 246);
    height: 25px
.star
  display: flex;

.img
  width: 18px;
  height: 18px;
  background-size: 100%;
.mint-button
  margin-right: 10px;
  &.cur
    >>> .mint-button-text
      color:#fff !important;
    background-color #009375!important;


.mint-button >>> .mint-button-text
  color: #111;
.switch
  margin-top: 45px;
  margin-left: 5px;
  font-size: 14px;
  color:#8e8989;

.mint-switch >>> .mint-switch-core
    border-color: #009375 !important;
    background-color: #009375 !important;
section
  > header
    padding-left: 15px;
    padding-bottom: 20px;
    padding-top:20px;
    border-bottom:1px solid #f3f4f6
.comments
  .comment-items
    margin: 20px 5px 0 5px;

    .comment-item
      margin-bottom: 32px;

      display: flex;
      .left_avatar
        margin-right: 15px;
        img
          width: 45px;
          height: 45px;
          border-radius: 50%;
      .right-content
        font-size:14px;
        width:80%;
        header
          display: flex;
          justify-content: space-between;
          align-items: center;
          .uname
            font-weight:bold
          .time
            font-size:14px;
            color:#8e8989;
        > section.content
          font-size:15px;
.img2
  width:14px;
  height:14px;

  background-size: 100%;
.mt10
  margin:10px 0;
.foot-btn
  >>> .mint-button-text
    color: #8e8989 !important;
  border: 1px solid #8e8989 !important;
  padding:0 5px
</style>
<style scoped></style>
